import re
import time

import requests

from conf import BASE_PATH


# def read_data_from_txt(file_path):
#     data_dict = {}
#     with open(file_path, 'r', encoding='utf-8') as file:
#         for line in file:
#             # 去除每行首尾的空白字符（包括换行符）
#             line = line.strip()
#             # 分割每行数据，假设每行数据由空格分隔
#             key, value = line.split(' ', 1)
#             # 将键值对存入字典
#             data_dict[key] = int(value)  # 假设值都是整数，故转换为int类型
#     return data_dict


def inform(Case_report, passed, failed_num, skipped, reruns, error_num, duration):
    # 个人机器人
    url = "https://open.feishu.cn/open-apis/bot/v2/hook/f062757b-b914-4e19-bd92-a1c2447dc45a"
    current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

    method = 'post'
    headers = {
        'Content-Type': 'application/json'
    }
    json = {
        "msg_type": "text",
        "content": {
            "text":
                "项目名称：云设计UI自动化测试\n"
                f"运行测试用例总数：{Case_report} \n"  # 使用 get 方法时提供默认值，以防键不存在  
                f"通过用例数：{passed} \n"
                f"失败用例数：{failed_num} \n"
                f"跳过用例数：{skipped} \n"
                f"异常用例数：{error_num} \n"
                f"重跑用例数：{reruns} \n"
                f"构建用时：{duration:.2f} 秒 \n"  # 提供默认值 0.0 以避免格式化错误  
                f"构建时间：{current_time}",

            "tag": "lark_md"
        }}
    rep = requests.request(method=method, url=url, headers=headers, json=json)
